package com.android.dopewars;

import java.util.Random;


public class Gun {
	public Gun(String name, int price, int low_damage, int high_damage) {
		name_ = name;
		price_ = price;
		low_damage_ = low_damage;
		high_damage_ = high_damage;
		rand_gen_ = new Random();
		rand_gen_.setSeed((int)name.charAt(0) + System.currentTimeMillis());
	}
	public Gun(Gun copy) {
		name_ = copy.name();
		price_ = copy.price();
		low_damage_ = copy.low_damage();
		high_damage_ = copy.high_damage();
		rand_gen_ = new Random();
		rand_gen_.setSeed((int)name_.charAt(0) + System.currentTimeMillis());
	}
	public Gun(String fromString) {
		valueFrom(fromString);
		rand_gen_ = new Random();
		rand_gen_.setSeed((int)name_.charAt(0) + System.currentTimeMillis());
	}
	
	public String name() { return name_; }
	public int price() { return price_; }
	public int damage() { return low_damage_ + (int)(rand_gen_.nextDouble() * (high_damage_ - low_damage_)); }
	public int low_damage() { return low_damage_; }
	public int high_damage() { return high_damage_; }
	
	public String toString() {
		String ret_val = new String();
		ret_val += name_;
		ret_val += "," + Integer.toString(price_);
		ret_val += "," + Integer.toString(low_damage_);
		ret_val += "," + Integer.toString(high_damage_);
		return ret_val;
	}
	public void valueFrom(String fromString) {
		String[] pieces = fromString.split(",");
		assert pieces.length == 4;
		name_ = pieces[0];
		price_ = Integer.valueOf(pieces[1]);
		low_damage_ = Integer.valueOf(pieces[2]);
		high_damage_ = Integer.valueOf(pieces[3]);
	}
	String name_;
	int price_;
	int low_damage_;
	int high_damage_;
	Random rand_gen_;
	
}
